#include <iostream>
#include <string.h>
#include "lab 4.h"

using namespace std;

int CWord::m_totalCharacters = 0;

CWord::CWord( CWord & CWord )
{
	m_pWord = new char[ strlen(CWord.m_pWord) + 1 ];
	strcpy( m_pWord, CWord.m_pWord );
	m_wordLen = CWord.m_wordLen;
	m_totalCharacters += m_wordLen;
}

CWord::CWord ( char *pWord )
{
	m_pWord = new char[ strlen(pWord) + 1 ];
	strcpy( m_pWord, pWord );
	m_wordLen = strlen( pWord );
	m_totalCharacters += m_wordLen;
}

CWord::~CWord ( void )
{
	delete [] m_pWord;
	m_totalCharacters -= m_wordLen;
}

CWord & CWord::operator = ( CWord &rhs )
{
	// paranoid check
	if ( this == &rhs )
		return *this;


	// Perform deep copy
	delete [] m_pWord; 
	m_totalCharacters -= m_wordLen;

	m_pWord = new char[ strlen(rhs.m_pWord) + 1 ];
	strcpy( m_pWord, rhs.m_pWord );
	m_wordLen = rhs.m_wordLen;
	m_totalCharacters += m_wordLen;

	// return...
	return *this;
}

void CWord::Display( void )
{
	cout << *this;
}

ostream & operator << ( ostream &os, CWord &rhs )
{
	os << "Word: " << rhs.m_pWord << endl;
	os << "Word Length: " <<  rhs.m_wordLen<< endl;

	return os;
}

void Function ( char word[5] )
{
	static int z =0;
	int x = strlen(word);
	z = z+x;

	cout<<z;
}

int  F2( int &r )
{
	int x =0;



	x= r+5;
	return x;
}


int main()
{

	if ( 0 )
	{
		int j = 6;
		F2(j);
		cout<<"**"<<F2(j)<<endl;//11

		j=j+1;

		cout<<"**"<<j<<endl;//23
		F2(j);
		cout<<"**"<<F2(j)<<endl;//28


		cout<<j<<endl<<endl;//23

		char word[5][5]={ "Mike", "ron", "tee", "doey", "pete" };
		int y =3;
		//cout<<word[1]<<endl;
		//
		Function( word[1] );
		cout<<endl;
		Function(word[2]);
		cout<<endl;
		Function(word[4]);
	}

	CWord word1("Brent"), word2("Andrew"), word3( "Word3" );

	cout << word1 << word2 << word3;

	(word1 = word3).Display();

	int x = 10;


	return 0;
	system("pause");
}
